package com.lph.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lph.dao.FilesDaoI;
import com.lph.dao.NoticesDaoI;
import com.lph.model.Files;
import com.lph.model.Msg;
import com.lph.model.Notices;
@Service
public class NoticesService implements BaseServiceI<Notices>{

	@Autowired
	private NoticesDaoI ndi;
	
	@Autowired
	private FilesDaoI fdi;
	public List<Notices> find(Notices t) {
		List<Notices> list=ndi.find(t);
		List<Notices> ns = new ArrayList<Notices>();
		for (Notices n : list) {
			Files f = new Files();
			f.setTname("t_coc_notices");
			f.setTid(n.getId());
			List<Files> fs = fdi.find(f);
			n.setFs(fs);		
			ns.add(n);
		}
		
		return ns;
	}

	public Notices get(Notices t) {
		List<Notices> list=this.find(t);
		
		return null;
	}

	public Msg insert(Notices t) {
		int i=ndi.insert(t);
		int size=this.find(new Notices()).size();
		Msg m=new Msg("插入失败", false);
		if (i>0) {
			m.setMsg("插入成功");
			m.setIs(true);
			m.setObject(size);
		}
		return m;
	}

	public Msg batchInsert(String objs) {
		// TODO Auto-generated method stub
		return null;
	}

	public Msg edit(Notices t) {
		int i=ndi.edit(t);
		Msg m=new Msg("更新失败", false);
		if (i>0) {
			m.setMsg("更新成功");
			m.setIs(true);
		}
		return m;
	}

	public Msg remove(Integer id) {
		int i=ndi.remove(id);
		Msg m=new Msg("删除失败", false);
		if (i>0) {
			m.setMsg("删除成功");
			m.setIs(true);
		}
		return m;
	}

	public Msg batchRemove(String ids) {
		// TODO Auto-generated method stub
		return null;
	}

}
